//
//  FDSystemTool.m
//  FD
//
//  Created by xiaofang wang on 2018/11/26.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "FDSystemTool.h"
#import <AudioToolbox/AudioToolbox.h>

@implementation FDSystemTool

+ (void)fd_virbrate {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}


+ (void)fd_makePhone:(NSString *)phone {
    FDLog(@"phone:%@",phone);
    //对字符串进行提纯
    phone = [NSString pureStrWithOriginStr:phone];
    FDLog(@"去除空格后的电话号码是:%@",phone);

    //    NSMutableString * str2 = [[NSMutableString alloc] initWithFormat:@"telprompt://1008611"]; //测试是否ok
    
    UIApplication *application = [UIApplication sharedApplication];
    if (@available(iOS 10.0, *)) {
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];
        NSURL *URL = [NSURL URLWithString:str];
        NSDictionary *dic = @{@"phone":phone};
        [application openURL:URL options:dic completionHandler:nil];
    } else {
        // Fallback on earlier versions
        NSMutableString * str2 = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",phone];
        [application openURL:[NSURL URLWithString:str2]];
    }
}



//+ (void)fd_makePhoneAlertWithVC:(UIViewController *)vc title:(NSString *)title phone:(NSString *)phone {
//
//    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:phone preferredStyle:(UIAlertControllerStyleAlert)];
//    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
//    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"拨打" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//
//        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];
//        UIApplication *application = [UIApplication sharedApplication];
//        NSURL *URL = [NSURL URLWithString:str];
//        NSDictionary *dic = @{@"phone":phone};
//
//        [application openURL:URL options:dic completionHandler:nil];
//    }];
//
//    [alertVC addAction:cancel];
//    [alertVC addAction:sure];
//
//    [vc presentViewController:alertVC animated:YES completion:nil];
//}
@end
